package com.managedBean;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import com.controller.OrderStatusController;

@ViewScoped
@ManagedBean(name = "orderStatus")
public class OrderStatusManagedBean implements Serializable {

	private static final long serialVersionUID = -8497924239311799115L;
	private String status;
	private String orderId;
	@ManagedProperty(value = "#{orderStatusController}")
	private OrderStatusController orderStatusController;

	@PostConstruct
	public void retrieveStatus() {
		HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
		orderId = request.getParameter("oid");
//		refresh();
	}
	
	public void refresh() {
		try {
			status = orderStatusController.retrieveOrderStatus(orderId);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status
	 *            the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * @return the orderId
	 */
	public String getOrderId() {
		return orderId;
	}

	/**
	 * @param orderId
	 *            the orderId to set
	 */
	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	/**
	 * @return the orderStatusController
	 */
	public OrderStatusController getOrderStatusController() {
		return orderStatusController;
	}

	/**
	 * @param orderStatusController
	 *            the orderStatusController to set
	 */
	public void setOrderStatusController(
			OrderStatusController orderStatusController) {
		this.orderStatusController = orderStatusController;
	}

}
